/*
 * @Author: GLNG
 * @Date: 2024-04-23 17:32:35
 * @LastEditors: GLNG
 * @LastEditTime: 2024-06-06 14:45:09
 * @FilePath: \signTool\mqttSignTool.js
 * @Description: 描述
 */
//TODO: update deviceId parameters 
var productKey = 'k0u5zY73hF9'
var deviceName = '867700072562249'
var deviceSecret = 'G7DDd0Jw48JxLpmo'
var ip = '1883'

var cryptojs = require('crypto-js');
var hmacsha1 = require('crypto-js/hmac-sha256');
var briefId = productKey + '.' + deviceName
var random = '1'
var instanceId = 'iot-060aamlx'
var clientId = briefId + '|securemode=' + -2 + ',authType=regnwl, signmethod=hmacsha256' + ',random=' + random + ',instanceId=' + instanceId + '|'
var username = deviceName + '&' + productKey
var plainText = 'deviceName' + deviceName + 'productKey' + productKey + 'random' + random
var mqttPort = productKey + '.iot-as-mqtt.cn-shanghai.aliyuncs.com'

function hmacSign (content, secret) {
  return hmacsha1(content, secret).toString();
}

var passwd = hmacSign(plainText, deviceSecret)

console.log('MQTTX配置参数')
console.log('阿里云免预注册：')
console.log('clientId:')
console.log(clientId)
console.log('mqttPort:')
console.log(mqttPort)
console.log('ip:')
console.log(ip)
console.log('username:')
console.log(username)
console.log('passwd:')
console.log(passwd)
console.log('plainText:')
console.log(plainText)
console.log('\r\n')
console.log('MQTTX生成的参数：newclientId、deviceToken')
console.log('阿里云MQTT连接参数：')
console.log('clientId:')
console.log('newclientId+|securemode=-2,authType=connwl|')
console.log('mqttPort:')
console.log(mqttPort)
console.log('ip:')
console.log(ip)
console.log('username:')
console.log(username)
console.log('username:')
console.log('deviceToken')
